package com.sgb.kjwl.viewmodel.home;

import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.model.entity.LeaseSearchResultTypeEntity;
import com.sgb.kjwl.repository.HomeRepertory;
import com.sgb.kjwl.view.ui.activity.ZulinSearchResultActivity;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class ZulinSearchResultModel extends BaseViewModel {
    private HomeRepertory repertory;
    private ZulinSearchResultActivity activity;

    public ZulinSearchResultModel(ZulinSearchResultActivity activity, HomeRepertory repertory) {
        this.activity = activity;
        this.repertory = repertory;
    }

    //租赁首页搜索的类目查询
    public void getLeaseType() {
        APIManager.getInstance().getLeaseAPI().getLeaseType()
                .enqueue(new Callback<BaseEntity<List<LeaseSearchResultTypeEntity>>>() {
                    @Override
                    public void onResponse(Call<BaseEntity<List<LeaseSearchResultTypeEntity>>> call, Response<BaseEntity<List<LeaseSearchResultTypeEntity>>> response) {
                        if (response.body() == null || response.body().getState() == null) {
                            return;
                        }
                        if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                            activity.updateViews(response.body().getData());
                        }

                    }

                    @Override
                    public void onFailure(Call<BaseEntity<List<LeaseSearchResultTypeEntity>>> call, Throwable t) {
                        t.printStackTrace();
                    }
                });
    }

}
